Enhancements for optimizing query executions

ABSTRACT

In an approach for optimizing query executions a processor receives a request to transfer data from a first table to a second table. A processor detects a relationship between the first table and the second table, wherein the relationship is based on a similarity between the first table and the second table. A processor identifies at least a first access path for transferring the data from the first table to the second table. A processor calculates a first cost of transferring the data from the first table to the second table using the first access path based on the similarity between the first table and the second table, wherein the first cost indicates estimated processor usage to transfer the data.

BACKGROUND

The present invention relates generally to the field of queryexecutions, and more particularly to enhancing query executions bychoosing a more efficient access path.

A query plan (or query execution plan) is an ordered set of steps usedto access data in a structured query language (SQL) relational databasemanagement system. The query is a specific case of the relational modelconcept of access paths. Since SQL is declarative, there are typically alarge number of alternative ways to execute a given query, with widelyvarying performance. When a query is submitted to the database, thequery optimizer evaluates some of the different, correct possible plansfor executing the query and returns what the query optimizer considersthe best alternative.

An access path refers to a path chosen by a system to retrieve dataafter a SQL request is executed. A query may request at least onevariable to be filled up with one or more values. Access path selectioncan have a tremendous impact on the overall performance of the system. Aquery can be a very simple query with one variable being matched tovalues from one table only, or a more complex query that may involvelooking for many variables which can be matched to many differentrecords on separate tables. Some of these variables even have complexconditions such as greater than or less than some value of integers.

Optimization of access path selection may be gauged using cost formulaswith input and output (I/O) and central processing unit (CPU)utilization weight usually considered. Generally, query optimizersevaluate the available paths to data retrieval and estimate the cost inexecuting the statements using the determined paths or a combination ofthese paths.

SUMMARY

Aspects of an embodiment of the present invention disclose an approachfor optimizing query executions. In one embodiment, a processor receivesa request to transfer data from a first table to a second table. In oneembodiment, a processor detects a relationship between the first tableand the second table, wherein the relationship is based on a similaritybetween the first table and the second table. In one embodiment, aprocessor identifies at least a first access path for transferring thedata from the first table to the second table. In one embodiment, aprocessor calculates a first cost of transferring the data from thefirst table to the second table using the first access path based on thesimilarity between the first table and the second table, wherein thefirst cost indicates estimated processor usage to transfer the data.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

FIG. 1 depicts a block diagram depicting a computing environment, inaccordance with one embodiment of the present invention.

FIG. 2 depicts a flowchart of the operational steps taken by optimizerprogram to calculate the cost for the access paths, within computingenvironment 100 of FIG. 1, in accordance with an embodiment of thepresent invention.

FIG. 3 depicts a flowchart of the operational steps taken by optimizerprogram to select an access path, within computing environment 100 ofFIG. 1, in accordance with an embodiment of the present invention.

FIG. 4 depicts a block diagram depicting the internal and externalcomponents of the server of FIG. 1, in accordance with one embodiment ofthe present invention.

DETAILED DESCRIPTION

As will be appreciated by one skilled in the art, aspects of the presentinvention may be embodied as a system, method or computer programproduct. Accordingly, aspects of the present invention may take the formof an entirely hardware embodiment, an entirely software embodiment(including firmware, resident software, micro-code, etc.) or anembodiment combining software and hardware aspects may generally bereferred to herein as a “circuit,” “module”, or “system.” Furthermore,aspects of the present invention may take the form of a computer programproduct embodied in one or more computer readable medium(s) havingcomputer readable program code/instructions embodied thereon.

Embodiments of the present invention discloses an approach to enhancingquery executions by choosing a more efficient access path. Thisinvention focuses on a method for path selection in queries based on theprocessing cost of the each path, which assists database choose a moreefficient access path.

The present invention will now be described in detail with reference tothe Figures.

FIG. 1 depicts a block diagram of computing environment 100 inaccordance with one embodiment of the present invention. FIG. 1 providesan illustration of one embodiment and does not imply any limitationsregarding computing environment 100 in which different embodiments maybe implemented. In the depicted embodiment, computing environment 100includes, but is not limited to and server 102. Computing environment100 may include additional computing devices, servers, computers,components, or additional devices not shown. It should be appreciatedFIG. 1 provides only an illustration of one implementation and does notimply any limitations with regard to the environments in which differentembodiments may be implemented. Many modifications to the depictedenvironment may be made.

Server 102 may be a management server, a web server, or additionalelectronic device or computing system capable of processing programinstructions and receiving and sending data. In other embodiments,server 102 may be a laptop computer, tablet computer, netbook computer,personal computer (PC), desktop computer, or any programmable electronicdevice. In additional embodiments, server 102 may represent a servercomputing system utilizing multiple computers as a server system, suchas in a cloud computing environment. In another embodiment, server 102represents a computing system utilizing clustered computers and nodes toact as a single pool of seamless resources. In the depicted embodiment,server 102 includes optimizer program 104 and database 110. Inadditional embodiments, server 102 may include and additional programs,storage devices, or components. Server 102 may include components, asdepicted and described in further detail with respect to FIG. 4.

Optimizer program 104 controls the calculation of different costsassociated with the queries, and the selection of the access pathassociated with each individual query. The query is a request for datafrom database 110 or another repository. The data the query is workingwith is in the form of tables. The query performs an action whichaffects the data in the tables. The query language is a series ofactions which, for example, modify the data in the tables, relocate thedata in the tables, or add/remove the data from the tables. An examplequery language is the statement INSERT FROM SELECT query. The INSERTFROM SELECT statement selects data from one table and inserts it into anexisting table. The different costs associated with the queries assistin determining the demand from the central processing unit (CPU). In oneembodiment, the lower the costs result in less work from the CPU.

Factors which affect the cost include the type of data which is beingtransferred, the relationship between the tables, and the order of thedata. Based on the query statements, data can be selected at random orsequential. Data selected at random typically has a higher CPU cost thandata selected in a sequential or logical order. Sequential data can alsobe divided into segments, or has a specified location within a table.The order of the data is determined by how the data is required to betransferred from the first table to the second table. In otherembodiments, the data is required to be transferred from the first tableto the second table in a specific order. In other embodiments, data isnot required to be transferred from the first table to the second tablein a specific or chronological order. Data which is required to betransferred in a specific order results in a higher cost, while datawhich does not require a specific order for transferring has a lowercost.

The relationship between the INSERT FROM SELECT tables is determined bythe connectivity of the tables. The connectivity of the tables isdefined by the similarity between the tables. Factors that determine thesimilarity between the tables can be, for example, table structure, orthe data in the table. Examples of aspects of the table structure whichaffect the similarity between the tables can be the rows, columns, sizeof the table, and other structural features of the table. Examples ofaspects of the data types in the table which affect the similaritybetween the tables can be, data topics, data complexity, format of thedata, or data type. A higher similarity between the data in the tablesresults in an easier transfer of data between the tables because the CPUhas fewer steps to transfer and reorganize the data.

In other embodiments, optimizer program 104, calculates the costsassociated with the queries, and the selection of the access pathassociated between more than two tables. In other embodiments, optimizerprogram 104 calculates the costs associated with the queries, and theselection of the access path associated between multiple tables inparallel. In other embodiments, optimizer program 104 selects the accesspath based on the calculation of all of these factors. In otherembodiments, optimizer program 104 selects the access path based on thecalculation from a selection of factors. In the depicted embodiment,optimizer program 104 includes cost function 106, and access function108. In another embodiments, cost function 106, and access function 108may be functions of additional programs, or standalone programs locatedon server 102 or additional servers, or computing devices, provided costfunction 106, and access function 108 are each accessible to optimizerprogram 104.

Cost function 106 calculates an estimate cost of the SELECT table andthe INSERT table. The cost of the SELECT table or the INSERT table iscalculated from a list of variables, for example, the type of data orthe table connectivity. In one embodiment, cost function 106 divides theestimation calculation into storage hardware device Direct accessstorage device (DASD) cost estimation, and a CPU cost estimation andmerges the two values to create the SELECT table or INSERT table cost.In other embodiments, cost function 106 calculates the DASD costestimation, for example, can be based on the locating of information,and necessary searching for the information either in a repository or ina cache. In other embodiments, cost function 106 calculates the CPU costestimation by, for example, dividing the cost estimation into a lockcost, scan cost, reserve cost, concurrency cost, and log cost. Thesecosts are dependent on the type of data, the order of the data, and thetable connectivity. A portion of these costs add up to give costfunction 106 the CPU cost which is used by access function 108 todetermine an efficient and effective access path. In other embodiments,cost function 106 uses these and other factors to calculate the CPUcost. In the depicted embodiment, cost function 106 is a function ofoptimizer program 104. In another embodiments, cost function 106 may bea standalone program located on server 102, or an additional computingdevice, provided cost function 106 is accessible to optimizer program104.

In another embodiment, cost function 106 checks the relationship betweenthe tables to determine the connectivity between the two tables. In oneembodiment, the tables are the data provided table, and the destinationtable. In other embodiments, there are more than two tables whereinformation is gathered from and placed in and cost function 106determines the connectivity between the tables. In one embodiment, costfunction 106 uses a foreign key detection to determine the relationshipbetween the columns and a primary key node (PKN) to determine therelationship of the workload. A PKN is a table that has a specialrelationship with the table or tables it is joined with. This specialrelationship allows for an easier transfer of information from one tableto the next, resulting in a higher connectivity between the two tables.In another embodiment, cost function 106 detects the connectivity of thetables by detecting the table structure. The table structure asdiscussed before has many different variables which determine thesimilarities and consistencies between the two tables.

Access function 108 controls the access path which is to be taken basedon the calculations of the cost function 106. The access path is theroute which optimizer program 104 uses to transfer data from the dataprovided table to the destination table. In other embodiments, accessfunction 108 locates more than one access path. In other embodiments,access function locates only one access path. Access function 108determines if the data provided has an order and based on the order ofthe data, calculates either a reduction to the cost, or calculates thecost with a sort plan and then selects an access path. Order of the datais related to the connectivity of the tables, and the random orsequential data in the tables. Depending on the order of the data,access function 108 may add a reduction factor into the cost. If areduction cannot be factored into the cost, access function 108 may usea sort plan factor into the cost. A sort plan is an addition cost factoradded on to the CPU cost calculation if the data requires a processwhich sorts or reorganizes the data prior to transferring the data fromthe data provided table to the destination table. In other embodiments,access function 108 may add both a reduction factor and incorporate asort plan as well. In the depicted embodiment, access function 108 is afunction of optimizer program 104. In another embodiments, accessfunction 108 may stand alone as a program located on server 102, or anadditional computing device, provided access function 108 is accessibleto optimizer program 104.

Database 110 may be a repository which may be written to and/or read byoptimizer program 104. In one embodiment, database 110 includes, forexample, the tables involved in the cost estimation, previous costestimations, relationships between components or elements, access pathsboth those used by optimizer program 104 and access paths not used byoptimizer program 104, and the selections made by optimizer program 104.In additional embodiments, database 110 may be written to and/or read byoptimizer program 104 and/or additional computing devices, servers,computers, components, or additional devices not shown. In oneembodiment, database 110 is a database management system (DBMS), used toallow the definition, creation, querying, update, and administration ofa database(s). In another embodiment, database 110 is a relationshipdatabase management system (RDMS). In the depicted embodiment, database110 is stored on server 102. In additional embodiments, database 110 mayreside on an alternative server, computer, or computing device, provideddatabase 110 is able to communicate with optimizer program 104 andadditional devices, programs, and components (not shown).

FIG. 2 depicts a flowchart of the operational steps taken by optimizerprogram to calculate the cost for the access paths, within computingenvironment 100 of FIG. 1, in accordance with an embodiment of thepresent invention. Flowchart 200 depicts the steps taken by costfunction 106 to estimate the cost for the access path. It should beappreciated FIG. 2 provides only an illustration of one implementationand does not imply any limitations with regard to the environments inwhich different embodiments may be implemented. Many modifications tothe depicted environment may be made.

In step 202, cost function 106 estimates the tables' cost. Cost function106 estimates the cost associated with transferring data in the INSERTFROM SELECT query statement. The cost associated with transferring datacorrelates to work performed by the CPU. A lower cost is associated withless work being performed by the CPU resulting in a faster transfer ofdata between the tables. A higher cost is associated with more workneeded to be performed by the CPU resulting in a slower, or longertransfer of data between the tables. A higher cost results in the CPUhaving to use more processing power to complete the transfer. A highercost can also result in a larger time period to complete the transfer.In one embodiment, cost function 106 estimates the cost in an INSERTFROM SELECT query. In this embodiment, cost function 106 estimates thecost of an INSERT table and a SELECT table.

In one embodiment, cost function 106 calculates the table cost from thedata type. In other embodiments, cost function 106 calculates the costof specific tables. In other embodiments, cost function 106 calculatesthe table cost, using the data type or other factors used to estimatethe CPU demand. In other embodiments, cost function 106 calculates thecost a single time. In other embodiments, cost function 106 calculatesthe cost multiple times and an average cost is calculated. The averagecost is used as the estimate cost for the tables involved. In otherembodiments, cost function 106 calculates the estimate cost for thetable a predetermined number of times, set by a third party or optimizerprogram 104. In other embodiments, cost function 106 gathers an estimatecost for the table from a repository if the data type, data order,connectivity between the tables, or other factors used to estimate theCPU demand for the SELECT table of the query are within a predeterminedthreshold to a prior cost estimation. This prior cost value is then usedin place of a calculated cost value. In other embodiments, cost function106 incorporates multipliers in the calculation. Examples of multiplierswhich are incorporated into the calculation can be, for example if thedata is sequential or segmented, if the data is concurrent, or if thereis a necessity for a query log. In one embodiment, cost function 106stores the SELECT table cost in a repository for future use.

In step 204, cost function 106 compares the relationship between thetables. Cost function 106 checks the relationship between the tables.This relationship assists in determining if the insert is sequential orrandom. The relationship between the tables is the connectivity orsimilarity of the tables. In another embodiment, cost function 106checks the relationship between the tables using a foreign key detectionto determine the relationship between the columns and a primary key node(PKN) to determine the relationship of the workload. A foreign key is aconstraint used to prevent actions that would destroy links within andbetween tables, or the foreign key is a constraint which preventsinvalid data from being inserted into a foreign key column establishedin a table. A PKN is a table that has a special relationship with thetable or tables it is joined with. This special relationship allows foran easier transfer of information from one table to the next, resultingin a higher connectivity between the two tables. In another embodiment,cost function 106 detects the connectivity of the tables by detectingthe table structure. In one embodiment, cost function 106 gathers therelationship between the two tables from a repository. In anotherembodiment, cost function 106 stores the calculated relationship betweenthe tables in a repository.

In step 206, cost function 106 identifies the access paths. Once costfunction 106 calculates the cost for the tables, cost function 106identifies access paths. An access path is the route which optimizerprogram 104 implements to complete the query. In one embodiment, costfunction 106 identifies a single access path. In one embodiment, costfunction 106 identifies a plurality of access paths. In one embodiment,cost function 106 identifies a plurality of access paths within apredetermined threshold, or exceeds a predetermined threshold for speedand efficiency. In some embodiment, cost function 106 identifies aplurality of access paths and sorts the access paths in terms of speed.In other embodiments, cost function 106 identifies a prior access pathstored in a repository. In another embodiment, cost function 106 storesthe identified access paths in a repository for future use.

FIG. 3 depicts a flowchart of the operational steps taken by optimizerprogram to select an access path, within computing environment 100 ofFIG. 1, in accordance with an embodiment of the present invention.Flowchart 300 depicts the selection of the access path. It should beappreciated FIG. 3 provides only an illustration of one implementationand does not imply any limitations with regard to the environments inwhich different embodiments may be implemented. Many modifications tothe depicted environment may be made.

In decision 302, access function 108 determines if the SELECT tableprovides order. The order of the table is how the data needs to betransferred from between tables. The order can be, for example,chronological, based on a hierarchy of information within the table, ordetermined by a foreign key restriction. The order is relevant todetermine the cost of the process and if reductions or additions arefactored into the cost. If access function 108 determines the SELECTtable provides order and cannot be performed randomly (Yes branch,proceed to step 304), access function 108 factors a reduction into thecost. If access function 108 determines the SELECT table does notprovides order (No branch, proceed to step 306), access function 108factors an addition into the cost.

In step 304, access function 108 calculates the cost with a reduction.The reduction is helpful is decreasing the cost of the operation andincreasing the number of potential access paths which can be used totransfer the data between the tables. In other embodiments, accessfunction 108 factors the reduction into the INSERT cost. In otherembodiments, access function 108 factors the reduction into the SELECTcost. In other embodiments, access function 108 subtracts the reductionfactor from the total cost of the operation. In other embodiments,access function 108 calculates the cost with a predetermined reductioncalculated into the cost. In other embodiments, access function 108calculates the cost with a variable reduction calculated into the cost.The variable reduction can be based on, for example, the amount of data,the order provided, and other factors which potentially affect the cost.

In decision 306, access function 108 determines if adding a sort plan iscost effective. The sort factor is a factor which is incorporated intothe overall cost. The sort plan is a process which adjusts the data inthe INSERT table if the INSERT table does not provide an order. The sortplan allows for faster transfer of information because the data issorted to be more easily transferred. If the cost with the sort plan isless than the cost without the sort plan (YES branch, proceed to step308), access function 108 adds the sort plan into the cost calculation.If the cost with the sort plan is greater than the cost without the sortplan (NO branch, proceed to 310), access function 108 does not add thesort plan into the cost calculation. In some embodiments, the sort plancost alteration is calculated into the INSERT table cost. If the sortplan cost is calculated into the INSERT table cost, cost function 106reorganizes the data to allow for fast transfer of information from theINSERT table to the SELECT table. In other embodiments, access function108 calculates a sort factor as predetermined value. In otherembodiments, access function 108 calculates the sort factor dependent onthe INSERT table and the SELECT table order, size, connectivity, andother factors.

In one embodiment, access function 108 calculates a cost without thesort factor, and also calculates a cost with the sort value and comparesthe two total costs. In some instances the total cost with the sortfactor may be less than the total cost without the sort factor, in whichcase access function 108 select the total cost with the sort factor. Thesort factor can also be factored into the total cost even if the SELECTtable provides and order to further lower the cost of the operation.

In step 308, access function 108 recalculates the cost with the sortplan. Access function 108 recalculates the cost with the sort planfactored into the cost. In one embodiments, the sort plan cost isfactored into the INSERT table cost. In other embodiments, the sort plancost is added to the cost of the INSERT table cost and SELECT tablecost. In yet another embodiment, the sort plan cost is factored into theINSERT table cost, and is added to the INSERT table cost and the SELECTtable cost.

In step 310, access function 108 selects an access path. Access function108 selects the access path to transfer the data from INSERT table toSELECT table. The path which access function 108 selects is based on thecost calculated and the availability of the CPU. A lower cost calculatedresults in a lower CPU demand and thus a greater number of potentialaccess paths for access function 108 to transfer the data between INSERTtable and SELECT table. If the cost calculated is higher there is agreater demand on the CPU which results in a lower number of potentialaccess paths to select from. Access function 108 selects the access pathto allow for an effective and efficient transfer of data. This may bethe fastest access path but does not necessarily have to be. For exampleaccess function 108 may wait to select an access path because thecalculated cost is greater than the cost of the available access paths.Access function 108 waits for an access path which can handle the CPUdemand to become available. In other embodiments, access function 108selects and access path which has a cost that is equal to or greaterthan a predetermined threshold value. In other embodiments, accessfunction 108 stores this information in a repository for future use.

FIG. 4 depicts a block diagram 400 of components of server 102, inaccordance with an illustrative embodiment of the present invention. Itshould be appreciated FIG. 4 provides only an illustration of oneimplementation and does not imply any limitations with regard to theenvironments in which different embodiments may be implemented. Manymodifications to the depicted environment may be made.

Server 102 includes communications fabric 402, which providescommunications between computer processor(s) 404, memory 406, persistentstorage 408, communications unit 410, and input/output (I/O)interface(s) 412. Communications fabric 402 may be implemented with anyarchitecture designed for passing data and/or control informationbetween processors (such as microprocessors, communications and networkprocessors, etc.), system memory, peripheral devices, and any additionalhardware components within a system. For example, communications fabric402 may be implemented with one or more buses.

Memory 406 and persistent storage 408 are computer-readable storagemedia. In one embodiment, memory 406 includes random access memory (RAM)and cache memory 414. In general, memory 406 can include any suitablevolatile or non-volatile computer-readable storage media.

Memory 406 is stored for execution by one or more of the respectivecomputer processors 404 of server 102 via one or more memories of memory406 of server 102. In the depicted embodiment, persistent storage 408includes a magnetic hard disk drive. Alternatively, or in addition to amagnetic hard disk drive, persistent storage 408 can include a solidstate hard drive, a semiconductor storage device, read-only memory(ROM), erasable programmable read-only memory (EPROM), flash memory, orany additional computer-readable storage media that is capable ofstoring program instructions or digital information.

The media used by persistent storage 408 may also be removable. Forexample, a removable hard drive may be used for persistent storage 408.Additional examples include optical and magnetic disks, thumb drives,and smart cards that are inserted into a drive for transfer onto anothercomputer-readable storage medium that is also part of persistent storage408.

Communications unit 410, in the examples, provides for communicationswith additional data processing systems or devices, including server102. In the examples, communications unit 410 includes one or morenetwork interface cards. Communications unit 410 may providecommunications through the use of either or both physical and wirelesscommunications links.

I/O interface(s) 412 allows for input and output of data with additionaldevices that may be connected to server 102. For example, I/O interface412 may provide a connection to external devices 416 such as a keyboard,keypad, camera, a touch screen, and/or some additional suitable inputdevice. External devices 416 can also include portable computer-readablestorage media such as, for example, thumb drives, portable optical ormagnetic disks, and memory cards. Software and data used to practiceembodiments of the present invention, e.g., optimizer program 104, costfunction 106, and access function 108 can each be stored on suchportable computer-readable storage media and can be loaded ontopersistent storage 408 of server 102 via I/O interface(s) 412 of server102. I/O interface(s) 412 also connect to a display 418.

Display 418 provides a mechanism to display data to a user and may be,for example, a computer monitor.

The present invention may be a system, a method, and/or a computerprogram product. The computer program product may include a computerreadable storage medium (or media) having computer readable programinstructions thereon for causing a processor to carry out aspects of thepresent invention.

The computer readable storage medium can be a tangible device that canretain and store instructions for use by an instruction executiondevice. The computer readable storage medium may be, for example, but isnot limited to, an electronic storage device, a magnetic storage device,an optical storage device, an electromagnetic storage device, asemiconductor storage device, or any suitable combination of theforegoing. A non-exhaustive list of more specific examples of thecomputer readable storage medium includes the following: a portablecomputer diskette, a hard disk, a random access memory (RAM), aread-only memory (ROM), an erasable programmable read-only memory (EPROMor Flash memory), a static random access memory (SRAM), a portablecompact disc read-only memory (CD-ROM), a digital versatile disk (DVD),a memory stick, a floppy disk, a mechanically encoded device such aspunch-cards or raised structures in a groove having instructionsrecorded thereon, and any suitable combination of the foregoing. Acomputer readable storage medium, as used herein, is not to be construedas being transitory signals per se, such as radio waves or additionalfreely propagating electromagnetic waves, electromagnetic wavespropagating through a waveguide or additional transmission media (e.g.,light pulses passing through a fiber-optic cable), or electrical signalstransmitted through a wire.

Computer readable program instructions described herein can bedownloaded to respective computing/processing devices from a computerreadable storage medium or to an external computer or external storagedevice via a network, for example, the Internet, a local area network, awide area network and/or a wireless network. The network may includecopper transmission cables, optical transmission fibers, wirelesstransmission, routers, firewalls, switches, gateway computers and/oredge servers. A network adapter card or network interface in eachcomputing/processing device receives computer readable programinstructions from the network and forwards the computer readable programinstructions for storage in a computer readable storage medium withinthe respective computing/processing device.

Computer readable program instructions for carrying out operations ofthe present invention may be assembler instructions,instruction-set-architecture (ISA) instructions, machine instructions,machine dependent instructions, microcode, firmware instructions,state-setting data, or either source code or object code written in anycombination of one or more programming languages, including an objectoriented programming language such as Smalltalk, C++ or the like, andconventional procedural programming languages, such as the “C”programming language or similar programming languages. The computerreadable program instructions may execute entirely on the user'scomputer, partly on the user's computer, as a stand-alone softwarepackage, partly on the user's computer and partly on a remote computeror entirely on the remote computer or server. In the latter scenario,the remote computer may be connected to the user's computer through anytype of network, including a local area network (LAN) or a wide areanetwork (WAN), or the connection may be made to an external computer(for example, through the Internet using an Internet Service Provider).In other embodiments, electronic circuitry including, for example,programmable logic circuitry, field-programmable gate arrays (FPGA), orprogrammable logic arrays (PLA) may execute the computer readableprogram instructions by utilizing state information of the computerreadable program instructions to personalize the electronic circuitry,to perform aspects of the present invention.

Aspects of the present invention are described herein with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems), and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer readable program instructions.

These computer readable program instructions may be provided to aprocessor of a general purpose computer, special purpose computer, oradditional programmable data processing apparatus to produce a machine,such that the instructions, which execute via the processor of thecomputer or additional programmable data processing apparatus, createmeans for implementing the functions/acts specified in the flowchartand/or block diagram block or blocks. These computer readable programinstructions may also be stored in a computer readable storage mediumthat can direct a computer, a programmable data processing apparatus,and/or additional devices to function in a particular manner, such thatthe computer readable storage medium having instructions stored thereincomprises an article of manufacture including instructions whichimplement aspects of the function/act specified in the flowchart and/orblock diagram block or blocks.

The computer readable program instructions may also be loaded onto acomputer, additional programmable data processing apparatus, oradditional device to cause a series of operational steps to be performedon the computer, additional programmable apparatus or additional deviceto produce a computer implemented process, such that the instructionswhich execute on the computer, additional programmable apparatus, oradditional device implement the functions/acts specified in theflowchart and/or block diagram block or blocks.

The flowchart and block diagrams in the Figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or table ofinstructions, which comprises one or more executable instructions forimplementing the specified logical function(s). In some alternativeimplementations, the functions noted in the block may occur out of theorder noted in the figures. For example, two blocks shown in successionmay, in fact, be executed substantially concurrently, or the blocks maysometimes be executed in the reverse order, depending upon thefunctionality involved. It will also be noted that each block of theblock diagrams and/or flowchart illustration, and combinations of blocksin the block diagrams and/or flowchart illustration, can be implementedby special purpose hardware-based systems that perform the specifiedfunctions or acts or carry out combinations of special purpose hardwareand computer instructions.

What is claimed is:
 1. A computer program product for optimizing queryexecutions, the computer program product comprising: one or morecomputer readable storage media and program instructions stored on theone or more computer readable storage media, the program instructionscomprising: program instructions to receive a request to transfer datafrom a first table to a second table; program instructions to detect arelationship between the first table and the second table, wherein therelationship is based on a similarity between the first table and thesecond table; program instructions to identify at least a first accesspath for transferring the data from the first table to the second table;and program instructions to calculate a first cost of transferring thedata from the first table to the second table using the first accesspath based on the similarity between the first table and the secondtable, wherein the first cost indicates estimated processor usage totransfer the data.
 2. The computer program product of claim 1, furthercomprising: program instructions to determine the first table providesan order corresponding to the second table; program instructions tocalculate a first reduction based on the first table providing an ordercorresponding to the second table; and program instructions to adjustthe first cost by first reduction.
 3. The computer program product ofclaim 1, further comprising: program instructions to select the firstaccess path to transfer the data from the first table to the secondtable.
 4. The computer program product of claim 1, further comprising:program instructions to determine the first table does not provide anorder corresponding to the second table; program instructions tocalculate a factor, based on the similarity between the first table andthe second table and the determination that the first table does notprovide an order corresponding to the second table, wherein the factorindicates a cost to reorganize the first table such that the data can betransferred to the second table; and program instructions to calculate asecond cost, wherein the second cost is the first cost adjusted by thesecond factor.
 5. The computer program product of claim 1, whereindetecting the relationship between the first table and the second table,further comprises: program instructions to match a data structure of thefirst table to a data structure of the second table; and programinstructions to compare contents of the first table to contents thesecond table.
 6. The computer program product of claim 1, furthercomprising: program instructions to determine that the first costexceeds a predetermined threshold; program instructions to identify asecond access path for transferring the data from the first table to thesecond table, wherein the second access path is currently inaccessible;program instructions to calculate a second cost of transferring the datafrom the first table to the second table using the second access pathbased on the similarity between the first table and the second table,wherein the second cost indicates estimated processor usage to transferthe data; program instructions to determine that the second cost iswithin the predetermined threshold; program instructions to monitor thesecond access path to determine availability of the second access path;program instructions to determine that the second access path isavailable; and responsive to determining that the second access path isavailable, program instructions to select the second access path totransfer the data from the first table to the second table.
 7. Acomputer system for optimizing query executions, the computer programproduct comprising: one or more computer processors, one or morecomputer readable storage media, and program instructions stored on theone or more computer readable storage media for execution by, at leastone of the one or more processors, the program instructions comprising:program instructions to receive a request to transfer data from a firsttable to a second table; program instructions to detect a relationshipbetween the first table and the second table, wherein the relationshipis based on a similarity between the first table and the second table;program instructions to identify at least a first access path fortransferring the data from the first table to the second table; andprogram instructions to calculate a first cost of transferring the datafrom the first table to the second table using the first access pathbased on the similarity between the first table and the second table,wherein the first cost indicates estimated processor usage to transferthe data.
 8. The computer system of claim 7, further comprising: programinstructions, stored on the computer readable storage media forexecution by at least one of the one or more processors, to determinethe first table provides an order corresponding to the second table;program instructions, stored on the computer readable storage media forexecution by at least one of the one or more processors, to calculate afirst reduction based on the first table providing an ordercorresponding to the second table; and program instructions, stored onthe computer readable storage media for execution by at least one of theone or more processors, to adjust the first cost by first reduction. 9.The computer system of claim 7, further comprising: programinstructions, stored on the computer readable storage media forexecution by at least one of the one or more processors, to select thefirst access path to transfer the data from the first table to thesecond table.
 10. The computer system of claim 7, further comprising:program instructions, stored on the computer readable storage media forexecution by at least one of the one or more processors, to determinethe first table does not provide an order corresponding to the secondtable; program instructions, stored on the computer readable storagemedia for execution by at least one of the one or more processors, tocalculate a factor, based on the similarity between the first table andthe second table and the determination that the first table does notprovide an order corresponding to the second table, wherein the factorindicates a cost to reorganize the first table such that the data can betransferred to the second table; and program instructions, stored on thecomputer readable storage media for execution by at least one of the oneor more processors, to calculate a second cost, wherein the second costis the first cost adjusted by the second factor.
 11. The computer systemof claim 7, wherein detecting the relationship between the first tableand the second table, further comprises: program instructions, stored onthe computer readable storage media for execution by at least one of theone or more processors, to match a data structure of the first table toa data structure of the second table; and program instructions, storedon the computer readable storage media for execution by at least one ofthe one or more processors, to compare contents of the first table tocontents the second table.